﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace WebApplication6
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!IsValid)
            {

                return;
            }

            //用户登录sql
            string sql = "select * from t_user where role='用户' and username='" + txtusername.Text
                + "' and password= '" + password.Text + "'  and suo='正常' ";

            DataTable dt = SQLHelper.ExecuteDataTable(sql);

            if (dt.Rows.Count <= 0) {
                Response.Write("<script language=javascript>alert('登录失败，用户名或者密码错误!');window.location.href='login.aspx';</script>");
                return;
            }

            string username =""; 
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                username = Convert.ToString(row["username"]);
 
            }

            Session["yonghu"] = username;
            Response.Write("<script language=javascript>alert('登录成功');window.location.href='index.aspx';</script>");
            return;
        }
    }
}
